$(function(){
	$("#my_return_order_datagrid").datagrid({    
	    url:'customer/return_business/myorder.do', 
	    loadMsg:'数据加载中···',
	    fit:'true',
	    idField:'id',
	    pagination:true,
	    rownumbers:true,//行号  
	    checkOnSelect : true,
		selectOnCheck : true,
	    columns:[[
	    {
	   		field : "ck",
	   		checkbox : true
		},  
		{
			field : "id",
			hidden : true
		},     
	    {
			field:'customer_no',
			title:'客户编号',
			width:200,
			align:'center'
	    },    
	    {
	    	field:'order_no',
	    	title:'订单编号',
	    	width:200,
	    	align:'center'
	     },
	     {
	    	 field:'order_fee',
	    	 title:'订单费用(美金)',
	    	 width:120,
	    	 align:'center',
	    	 formatter:function(value, row, index){
	    		 if(row['state']==4){
	    			 return row['laborFee']+row['postage'];
	    		 }else{
	    			 return "--";
	    		 }
	    	 }
	    },
	     {
	    	 field:'business_type',
	    	 title:'订单业务类型',
	    	 width:140,
	    	 align:'center',
	    },{

	    	field:'state',
	    	title:'订单处理状态',
	    	width:100,
	    	align:'center',
	    	 formatter:function(value, row, index){
	    		 if(value==0)
	    			 return "待审核";
	    		 else if(value==1)
	    			 return "审核中";
	    		 else if(value==2)
	    			 return "收货中";
	    		 else if(value==3)
	    			 return "退货中";
	    		 else if(value==4)
	    			 return "待付款";
	    		 else if(value==5)
	    			 return "发货中";
	    		 else if(value==6)
	    			 return "完成中";
	    	 }
	    },{
   	    	field:'create_tm',
   	    	title:'下单时间',
   	    	width:200,
   	    	align:'center',
   	        formatter: function(value,row,index){
   	        	return getTime(value);
   	        }},
	     {
	    	 field:'order_pay',
	    	 title:'付款',
	    	 width:100,
	    	 align:'center',
	   	        formatter: function(value,row,index){
	   	        	if(row.state==4){
	   	        		return "<a style='color:red' target='_blank' href='https://auth.alipay.com/login/index.htm'>支付宝</a>|"+
	   	        		"<a style='color:red' target='_blank' href='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PQPQJNXGSLLNN'>PayPal</a>";
	   	        	}else{
	   	        		return "--";
	   	        	}
	   	   },
	     },{

		    	field:'detail_check',
		    	title:'订单查看',
		    	width:100,
		    	align:'center', 
		    	formatter:function(value, row, index){
		    		return "<a href='javascript:void(0)' onclick=\"showRetDetail('"+row.order_no+"')\">查看详情</a>";
		    	}
		    }
	    ]],
	    fitColumns:true,
	    toolbar:'#add_ret_sup_tb'
	});  	
});
function showRetDetail(order_no){
	$("#ret_detail_dialog").dialog({    
	    title: '查看订单详情',    
	    width: 650,   
	    height: 600,
	    closed: false,    
	    cache: false,
	    iconCls:'icon-eye',
	    href: 'customer/return_business/show_detail?order_no='+order_no,    
	    modal: true,
	    buttons:[{
			text:'关闭',
			handler:function(){
				$("#ret_detail_dialog").dialog('close');
				$("#my_return_order_datagrid").datagrid('uncheckAll');
			}
		}]   
	});    
}
function showRetFiles(index){
	var row = $('#my_return_order_datagrid').datagrid('getData').rows[index];
	var str="<div align='center'>";
	var count = 0;
	if(row.rec_tab_name!=""){
		str += "<a target='_blank' href='"+$("input[name='filePath']").val()+row.rec_tab_name+"'>收货统计表</a><br/><br/>";
	}else{
		count++;
	}
	if(row.arr_tab_name!=""){
		str += "<a target='_blank' href='"+$("input[name='filePath']").val()+row.arr_tab_name+"'>到货数量统计表</a><br/><br/>";
	}else{
		count++;
	}
	if(row.check_result_tab_name!=""){
		str += "<a target='_blank' href='"+$("input[name='filePath']").val()+row.check_result_tab_name+"'>退货检测结果表</a><br/><br/>";
	}else{
		count++;
	}
	if(row.ret_scrap_tab_name!=""){
		str += "<a target='_blank' href='"+$("input[name='filePath']").val()+row.ret_scrap_tab_name+"'>退货报废表</a><br/><br/>";
	}else{
		count++;
	}
	if(row.ret_fee_tab_name!=""){
		str += "<a target='_blank' href="+$("input[name='filePath']").val()+row.ret_fee_tab_name+">退货费用和邮费表</a><br/><br/>";
	}else{
		count++;
	}
	if(row.logis_tab_name!=""){
		str += "<a target='_blank' href="+$("input[name='filePath']").val()+row.logis_tab_name+">发货物流单号表</a><br/><br/>";
	}else{
		count++;
	}
	if(count==6){
		str+="暂未上传！";
	}	
	str+="</div>";
	$.messager.alert('文件信息',str);
}
function getTime(old) {
	var date = new Date(old);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	if (month < 10)
		month = "0" + month;
	var day = date.getDate();
	if (day < 10)
		day = "0" + day;
	var hour = date.getHours();
	if (hour < 10)
		hour = "0" + hour;
	var minute = date.getMinutes();
	if (minute < 10)
		minute = "0" + minute;
	var seconds = date.getSeconds();
	if (seconds < 10)
		seconds = "0" + seconds;
	var newDate = year + "-" + month + "-" + day + " " + hour + ":" + minute
			+ ":" + seconds;
	return newDate;
}
/**查询条件*/
function queryRet(){
	$("#my_return_order_datagrid").datagrid({
		queryParams: {
			orderNo: $("input[name='retOrderNo']").val(),
			tmFrom : $("input[name='retTmFrom']").val(),
			tmTo : $("input[name='retTmTo']").val()
		}
	});
}
function resetRet(){
	$("input[name='retOrderNo']").val("");
	$("input[name='retTmFrom']").val("");
	$("input[name='retTmTo']").val("");
	$("#retTmFrom").datebox("setValue","");
	$("#retTmTo").datebox("setValue","");
	queryRet();
}
function addRetSup(){
	var rows = $("#my_return_order_datagrid").datagrid('getChecked');
	if (rows && rows.length == 1) {
			
		   $("#add_ret_sup").dialog({    
		    title: '提交补充文档',    
		    width: 500,   
		    height: 550,
		    closed: false,    
		    cache: false,
		    iconCls:'icon-add',
		    href: 'customer/return_business/toSup?order_no='+rows[0].order_no,    
		    modal: true   
		});    
	} else {
		parent.$.messager.alert('提示', "请选择一条订单信息！");
	}
	$("#my_return_order_datagrid").datagrid('uncheckAll');
}